//
//  AppDelegate.swift
//  SinaWeiBo
//
//  Created by tuyue on 16/3/5.
//  Copyright © 2016年 xueyang.co.ltd. All rights reserved.
//

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    
    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
       
        //MARK: - 设置全局navBar和tabBar的颜色
        setupAppearance()
        //MARK: 实例化Window
        registerNotification()
        /**给window设置frame*/
        window = UIWindow(frame: UIScreen.mainScreen().bounds)
        
        /**设置初始化window的背景颜色*/
        window?.backgroundColor = UIColor.whiteColor()
       
        /**给window设置初始化控制器*/
         defaultViewController()
//        window?.rootViewController = MainViewController()
//        window?.rootViewController = WelcomeViewController
        
        
        
        /**window的可视化*/
        window?.makeKeyAndVisible()
        return true
    }
    
    /**设置全局navBar和tabBar的颜色*/
    private  func setupAppearance(){
    UITabBar.appearance().tintColor = themeColor
    UINavigationBar.appearance().tintColor = themeColor
    }
    
    private func defaultViewController(){
        /**判断如果UserLogin是true(asscess_token有值的时候)进入欢迎界面，没有值就进入主界面*/
//        let defaultVC = UserAccount.sharedAccount.userLogin ? WelcomeViewController() : MainViewController()
//         /**设置初始化控制器*/
//         window?.rootViewController = defaultVC
         
         
        let nowVC = UINavigationController(rootViewController: ComposeViewController())
        window?.rootViewController = nowVC
//        let nowVC = UINavigationController(rootViewController: PictureSelectorController())
//        window?.rootViewController = nowVC
       
    }
    
    /**更改控制器，当object为nil时候，将跟控制器设置为Main，如果不为nil，将根控制器设为welcome*/
    @objc private func changeRootViewController(n: NSNotification){
        //    let object = n.object
        window?.rootViewController = (n.object == nil) ? MainViewController() : WelcomeViewController()
    }
 
    
     /**注册通知，接收通知 调取方法*/
    private func registerNotification(){
        
     NSNotificationCenter.defaultCenter().addObserver(self, selector: "changeRootViewController:", name: SwitchRootViewController, object: nil)
        
    }
    
   /**更改控制器，当object为nil时候，将跟控制器设置为Main，如果不为nil，将根控制器设为welcome*/

    
    
    deinit {
    NSNotificationCenter.defaultCenter().removeObserver(self)
    }

}

